﻿<%@ LANGUAGE = VBScript.Encode %>
<%
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
%>
<!--#include file="..\CheckSession.inc"-->
<!--#include file=..\getFormName.inc-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Tìm kiếm người nhận</title>
<body topmargin=0 leftmargin=0 bgcolor=#F8F9D9 onload="SetFocus()">
	<form name=frm method=post action="frmNguoinhan.asp?bSearch=ok">
		<table width="100%" border=0>
			<tr>
				<td width="70%">
                <input name=Txt style="font-family:times new roman;width:100%" size="20"></td>
				<td width="30%"><input name=Cmd value=Search Type=submit style="font-family:times new roman;width:100%"></td>
			</tr>
		</table>		
<%
			if request("bSearch")="ok" then
				btxt=Request("Txt")
				sSQL="select hovaten,email from canbo"
				sSQL=sSQL+" where hovaten like '%"& replace(bTxt ,"'","''") &"%' "
				sSQL=sSQL+" union all "
				sSQL=sSQL+"select tendoitac,email from doitac"
				sSQL=sSQL+" where tendoitac like '%"& replace(bTxt ,"'","''") &"%' "
				sSQL=sSQL+" union all "
				sSQL=sSQL+"select ten,email from doitac_nguoi"
				sSQL=sSQL+" where ten like '%"& replace(bTxt ,"'","''") &"%' "
			else
				sSQL="select hovaten,email from canbo"
				sSQL=sSQL+" union all "
				sSQL=sSQL+"select tendoitac,email from doitac"
				sSQL=sSQL+" union all "
				sSQL=sSQL+"select ten,email from doitac_nguoi"
			end if
			Set RecTC=Server.CreateObject("ADODB.Recordset")
			RecTC.CursorType=3
			RecTC.CacheSize=5
			RecTC.Open sSQL,Conn
%>
				<select ondblclick="javaScript:doSelect()" size="8"  name="List" style="font-family:times new roman; width: 100%; border-style: solid; border-width: 1; padding-left: 0; background-color: #FFFFFF; height:280" onkeyup="return List_onkeyup()">
<%
			Do While not RecTC.EOF
%>
				<%if trim(RecTC("email"))<>"" then%>
					<option value="<%=trim(RecTC("email"))%>"><%=trim(RecTC("hovaten"))%> (<%=trim(RecTC("email"))%>)</option>
				<%end if%>
<%
				RecTC.movenext
			Loop
%>
		</select>
	</form>
</body>
<script language=javascript>
function doSelect() {
	var sValue;
	sValue = document.forms[1].List.value;

	if ("" + sValue != "") {
		window.close();
		if (window.opener) { 
			temp=window.opener.document.frm.ToEmail.value;
			if  (temp!=""){
				temp=temp+";"
			}
			window.opener.document.frm.ToEmail.value=temp+sValue;
			//window.opener.document.frm.ToEmail.value=sValue;
//			window.opener.focus();
			window.opener.document.frm.ToEmail.focus();
		}
	}
}	

function SetFocus(){
	document.frm.Txt.focus();
}

function List_onkeyup(){
var keycode
keycode=window.event.keyCode
if (keycode==13) {
	doSelect();
}
}
    </script>